<?php
include("config.php");

session_start();
// if(!isset($_SESSION['user_id']))
// 	header('location:index.php');
if(!isset($_SESSION['username']))
	header('location:index.php');
error_reporting(1);
?>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="bg" lang="bg">
<head>
	<title><?php echo mb_convert_encoding('Вътрешна система за autohit','Windows-1251','UTF-8'); ?></title>
	<meta http-equiv="content-type" content="text/html; charset=Windows-1251" />

	<!-- Scripts -->
	<script type='text/javascript' src='js/scripts.js'></script>

	<!-- Style -->
	<link rel="stylesheet" type="text/css" href="css/styles.css" />
	<style>a{ text-decoration: none; color: black; }</style>
</head>
<body>
	<div id="table_product_result" style = "width:100%;">
<?php
$id = $_GET['id'].'_'.$_GET['dealer_id'];

	if(isset($_SESSION['articleGroupsDealers'][$id]))
	{
?>
		<table class="hovertable" width="100%" style="border-collapse: collapse; font-size: 14px;" cellspacing="10">
			<tr>
				<th height="40" style="width:10%; border-bottom: 2px solid #000000;"><?php echo mb_convert_encoding('Продукт №','Windows-1251','UTF-8'); ?></th>
				<th height="40" style="width:10%; border-bottom: 2px solid #000000;"><?php echo mb_convert_encoding('Артикулен номер','Windows-1251','UTF-8'); ?></th>
				<th height="40" style="width:20%; border-bottom: 2px solid #000000;"><?php echo mb_convert_encoding('Наименование','Windows-1251','UTF-8'); ?></th>
				<th height="40" style="width:20%; border-bottom: 2px solid #000000;"><?php echo mb_convert_encoding('Описание','Windows-1251','UTF-8'); ?></th>
				<th height="40" style="width:15%; border-bottom: 2px solid #000000;"><?php echo mb_convert_encoding('Снимка','Windows-1251','UTF-8'); ?></th>
				<th height="40" style="width:35%; border-bottom: 2px solid #000000;"><?php echo mb_convert_encoding('Допълнителна информация','Windows-1251','UTF-8'); ?></th>
			</tr>
<?php
		$i = 0;
		$j = 0;
		
		$articleGroupsDealers = $_SESSION['articleGroupsDealers'][$id];
		if(!is_array($articleGroupsDealers->article))
			$articleGroupsDealers->article = array($articleGroupsDealers->article);
		foreach($articleGroupsDealers->article as $key => $group_dealer)
		{
		
			$j++;
?>
			<div id="<?php echo $key;?>">
<?php
					$i++;
					$bgcolor = ( (($i+j) % 2 ==0) ? "#ffffff" : "#eeeeee");
?>
					<tr bgcolor="<?php echo $bgcolor; ?>" onmouseover="this.style.cursor='pointer'; this.style.backgroundColor='#d9d1fd';" onmouseout="this.style.cursor='normal'; this.style.backgroundColor='<?php echo $bgcolor; ?>';">
						<td height="30" style="text-align: center;"><?php echo $group_dealer->id; ?></td>
						<td height="30" style="text-align: center;"><?php echo $group_dealer->articleNumber; ?></td>
						<td height="30" style="text-align: center;"><?php echo $group_dealer->dealerName; ?></td>
						<td height="30" style="text-align: center;"><?php echo $group_dealer->articleGroupName; ?></td>
						<td height="30" style="text-align: center;"><?php echo ( (!empty($group_dealer->picture)) ? "<img src='".$group_dealer->picture."' width='150' height='120' />" : "<img src='images/noimage.jpg' width='150' height='120' />"); ?></td>
						<td height="30" style="text-align: left;">
							<?php
								foreach($group_dealer->criteria as $key => $value){
									if($value->value){
							?>
										<div><?php echo $value->label.' - '.$value->value; ?></div>
							<?php
									}
									else{
							?>
										<div><?php echo $value->label; ?></div>
							<?php
									}
								}
							?>
						</td>
					</tr>
			</div>
<?php
			}
?>
			</table>
<?php
		}
?>
	</div>
</body>
</html>